<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test-1</title>
    <style>
        html,
        body {
            height: 100%;
        }

        body {
            margin: 0;
        }

        .w {
            width: 960px;
            margin: 0 auto;
        }

        ul,
        ol {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .nav {
            height: 100px;
            background-color: rgba(255, 255, 255, .3);
        }

        .nav ul {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100px;
        }

        .nav li {
            width: 120px;
            height: 80px;
            line-height: 80px;
            border-radius: 5px;
            overflow: hidden;
            background-color: #ccc;
            margin: 0 10px;
            border: 3px solid #fff;
            cursor: pointer;
        }

        .nav li.active {
            border: 3px solid #f50;
        }

        .nav li img {
            width: 120px;
            vertical-align: middle;
        }

        body {
            background-image: url(./img/photo1.jpg);
            background-size: cover;
        }
    </style>
</head>

<body>
    <div class="nav">
        <div class="w">
            <ul>
                <li class="active"><img src="./img/photo1.jpg" alt=""></li>
                <li><img src="./img/photo2.jpg" alt=""></li>
                <li><img src="./img/photo3.jpg" alt=""></li>
                <li><img src="./img/photo4.jpg" alt=""></li>
                <li><img src="./img/photo5.jpg" alt=""></li>
            </ul>
        </div>
    </div>


    <script type="text/javascript">
        // 分值：10分
        // 要求：
        // 功能：切换主题（背景）
        // 鼠标移入缩略图，当前缩略图边框高亮，非当前缩略图移除边框高亮
        // 鼠标移入缩略图，页面显示与之相应的背景
        // 根据所学知识点完成功能

        // 评分：可有多种实现方式，实现功能即可！
        // var nav = document.querySelector(".nav");
        // var w = document.querySelector(".w");
        // var li = document.querySelectorAll(".w ul li");
        // var body_1 = document.querySelector("body");

        var li = document.querySelectorAll("li");
        var body = document.querySelector("body");

        // var index = 0;
        // var square = 0;

        // var setPoint = function (key) {
        //     for (var i = 0; i < li.length; i++) {
        //         li[i].className = "";
        //     }
        //     li[key].className = "active";
        // }

        // for(var j = 0 ; j < li.length ; j ++) {
        //     li[j].aaa = j ;
        //     li[j].onmouseenter = function () {
        //         index = this.aaa +1;
        //         body_1.style["backgroundImage"] = "url(./img/photo"+index+".jpg)";
        //         square = this.aaa;
        //         setPoint(square);
        //     }
        // }

        var index = 0 ;

        var setPoint = function (key) {
            for (var i = 0 ; i < li.length ; i ++) {
                li[i].className = "";
            }
            li[key].className = "active";
        }

        var backchange = function () {
            var _this = this;
            for(var j =0 ; j < li.length; j ++) {
                li[j].aaa = j ;
                // console.log(j);
                li[j].onmouseenter = function () {
                    _this.index = this.aaa + 1 ;
                    body.style["backgroundImage"] = "url(./img/photo"+_this.index+".jpg)";
                    square = this.aaa ; 
                    setPoint(square);
                }
            }
        }

        backchange();
    </script>
</body>

</html>